﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class ExcelImportandExport : DemoBaseUserControl
    {
        public ExcelImportandExport()
        {
            InitializeComponent();
            this.Title = "Excel 导入导出";
            this.Description = "Spread .NET  可以与 Excel 格式文件良好的兼容，点击下面按钮执行导入导出 Excel 格式文件。";
        }

        private void butExport_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "保存 Spread 为 Excel 格式";
            saveFileDialog1.Filter = "Excel 文件 | *.xls";

            if (saveFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
            {

                string fileName = saveFileDialog1.FileName;
                fpSpread1.SaveExcel(fileName);
            }
        }

        private void butImport_Click(object sender, EventArgs e)
        {
            string defaultCommonPath = Application.StartupPath;// default XML path
            openFileDialog1.InitialDirectory = defaultCommonPath;
            openFileDialog1.Title = "导入 Excel 文件到 Spread 中";
            openFileDialog1.Filter = "Excel 文件| *.xls";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fileName = openFileDialog1.FileName;
                fpSpread1.OpenExcel(fileName);
            }
        }

        private void ExcelImportandExport_Load(object sender, EventArgs e)
        {
            this.fpSpread1_Sheet1.Columns.Count = 20;
            this.fpSpread1_Sheet1.Rows.Count = 40;
            this.fpSpread1_Sheet1.Cells[0, 0].ForeColor = System.Drawing.Color.Red;
            this.fpSpread1_Sheet1.Cells.Get(0, 0).Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold);
            this.fpSpread1_Sheet1.Cells.Get(0, 0).Text = "请单击“Excel导入”按钮导入Excel样例";
            this.fpSpread1_Sheet1.Cells.Get(0, 0).Column.Width = this.fpSpread1_Sheet1.Columns.Get(0).GetPreferredWidth();
            this.fpSpread1_Sheet1.Cells.Get(0, 0).Row.Height = 100;
            this.fpSpread1_Sheet1.Cells.Get(0, 0).VerticalAlignment = FarPoint.Win.Spread.CellVerticalAlignment.Center;
            this.fpSpread1_Sheet1.Cells.Get(0, 0).HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center;
        }
    }
}
